var contextpath = $("#hid_contextpath").val();
var imgSize = 20 * 1024;
$('#attachment_file_upload').uploadify({
			'uploader' : contextpath+ '/ipiinclude/ipiplugin/uploadify/scripts/uploadify.swf?ver=' + Math.random(),
			'script' : contextpath+ '/file/upload;jsessionid='+$("#session_id").val(),
			'cancelImg' : contextpath+ '/ipiinclude/ipiplugin/uploadify/cancel.png',
			'buttonImg' : contextpath+ '/ipiinclude/ipiplugin/uploadify/upload_pitcure.png',
			'sizeLimit' :imgSize,
			'multi' : false,
			'auto' : true,
			'fileDesc' : '*.jpg',
			'fileExt' : '*.jpg',
			'queueID' : 'custom-queue',
			'queueSizeLimit' : 1,
			'simUploadLimit' : 1,
			'removeCompleted' : false,
			'onOpen' : function(event, queueId, fileObj){
			},
			'onSelectOnce' : function(event, data) {
				$("#hasUploadAttachmentFile").val(1);
			},
			'onComplete' : function(event, queueId, fileObj, response, data) {
				response = eval('(' + response + ')');
				
				if(response.uploadFlag == true){
					alertMsg('图片上传成功');
					
					//上传成功，先删除原来的图像
					//if($("#attachmentFileName").val != "")
						//deleteFlie($("#attachmentFileName").val());
						
					$("#attachmentFilePath").val(response.filePath);
					$("#attachmentFileName").val(response.fileName);
					$("#userImg").attr("src","ipiimg/userimg/"+response.fileName);
				}else{
					alertMsg(response.errerMsg);
				}
				
			},
			'onError' : function(event, ID, fileObj, errorObj) {
				//console.log(errorObj.type+" "+errorObj.info);
				if((fileObj.size) > imgSize){
					alertMsg('上传图片超过最大限制！');
				}else if(errorObj.type == "HTTP" && errorObj.info == "404"){
					alertMsg('图片只支持jpg格式，请重新上传！');
				}else{
					alertMsg('上传图片失败，请稍后重试');
				}
			},
			'onCancel' : function(event, ID, fileObj, errorObj) {
				deleteFlie($("#attachmentFileName").val());
				$("#attachmentFilePath").val("");
				$("#attachmentFileName").val("");
				$("#hasUploadAttachmentFile").val(0);
			},
			'onClearQueue' : function(event, ID, fileObj, errorObj) {
			}
		});

function deleteFlie(fileName){
	$.post("file/delete", {
				'fileName' : fileName
			});
} 